//
//  IncidentCell.m
//  Runone
//
//  Created by runone02 on 16/8/27.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "IncidentCell.h"

@implementation IncidentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

+ (instancetype)incidentCell
{
    return [[[NSBundle mainBundle] loadNibNamed:@"incidentCell" owner:nil options:nil] firstObject];
}

- (void)setCellData:(CurrentEvent *)data {
    //事件
    NSInteger type = data.IncidentType ;
    if (type == 1) {
        self.firstLabel.text  = @"事故事件";
    }else if(type == 4) {
        self.firstLabel.text  = @"施工事件";
    }else {
        self.firstLabel.text  = @"上报事件";
    }
    //方向
    NSInteger derection = [data.RoadDerection integerValue];
    if (derection == 1) {
        self.secondLabel.text = @"广州方向";
    }else {
        self.secondLabel.text = @"湖南方向";
    }
    self.thirdLabel.text  = [NSString stringWithFormat:@"事件详情：%@",data.IncidentDetail];
    self.timeLabel.text   = [NSString stringWithFormat:@"时间：%@",data.RecordTime];
    //图片
    self.iconView.image = [UIImage imageNamed:@"广乐高速-副本-2"];
    self.EventStateLabel.hidden =YES;
}

- (void)setCellTollData:(TollEvent *)tollData {
    self.firstLabel.text = @"收费事件";
    self.secondLabel.text = tollData.TollStationName;
    self.thirdLabel.text = tollData.DutyMonitor;
    self.timeLabel.text = tollData.OccurTime;
    //图片
    self.iconView.image = [UIImage imageNamed:@"广乐高速-副本-2"];
    self.EventStateLabel.hidden = YES;
}

////dataValueString	__NSCFString *	@"{\"EventUID\":\"8a3e007e-9daf-4938-8fcd-84f59864a50b\",\"SystemUID\":\"4a22bbfd-428c-495c-9702-af5fb92c3973\",\"TollStationUID\":\"e5197f70-7eba-4dae-8046-d1126af7c4ab\",\"EventType\":0,\"DutyMonitor\":\"马蓉\",\"OccurTime\":\"2016-08-19 00:00:00\",\"EventDescription\":\"马蓉冲卡\",\"PicturesInfo\":null,\"VideoInfo\":null,\"RecordUserUID\":\"419c6bd7-cb02-4a03-a3a4-944289d50d7b\",\"RecordTime\":\"2016-08-19 09:18:12\",\"SystemCode\":\"GuangleHighway\",\"TollStationName\":\"坪石西收费站\",\"TollStationInfo\":null}"
- (void)setCellReportData:(ReportEvent *)reportedData {
    
    NSInteger type = reportedData.IncidentType ;
    if (type == 1) {
        self.firstLabel.text  = @"事故事件";
    }else if(type == 4) {
        self.firstLabel.text  = @"施工事件";
    }else {
        self.firstLabel.text  = @"上报事件";
    }
    self.secondLabel.text = [NSString stringWithFormat:@"上报人：%@",reportedData.RecordUserName];
    self.thirdLabel.text = [NSString stringWithFormat:@"部门：%@",reportedData.RecordUserOrgName];
    self.iconView.image = [UIImage imageNamed:@"广乐高速-副本-2"];
    self.timeLabel.text   = [NSString stringWithFormat:@"更新时间：%@",reportedData.RecordTime];
#pragma mark - 判断事件状态
    NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *occurData =[dateFormat dateFromString:reportedData.OccurTime];
    NSDate *endData =[dateFormat dateFromString:reportedData.EndTime];
    NSDate * now = [NSDate date];
   
    NSComparisonResult result1 = [now compare:occurData];
    NSComparisonResult result2 = [now compare:endData];
    NSString *stateStr = nil;
    if (result1 == NSOrderedAscending) {
        NSLog(@"未开始");
        stateStr = @"未开始";
    }else if (result2 == NSOrderedAscending || result1 == NSOrderedDescending) {
        NSLog(@"进行中");
         stateStr = @"进行中";
    }else {
        NSLog(@"已结束");
        stateStr = @"已结束";
    }
    self.EventStateLabel.text = stateStr;
    
}





@end
